You may think that pointers are not that useful. However, think back to functions and parameters. We had decided that in C functions have a serious limitation. This is that you can only ever send information into a function. Sometimes you like your functions to change the contents of variables for you. This is often required when the function needs to return a number of results.
You can get functions to change variables by making the parameters of the function pointers. The code in the function can then follow these pointers to the variables which need changing:
void swapper ( int * a, int * b ) { int temp = *a ; *a = *b ; *b = temp ; }
This is a mind blowing piece of code, but it is actually quite useful. It swaps the values of two variables around:
int i = 3, j = 4 ; swapper ( &i, &j ) ;
Note that when I call the function I have to feed in the addresses of the parameters, not the parameters themselves. After I have called swapper I find that i contains 4 and j contains 3. Swapper uses a temporary variable to hold a while the swap is performed. On the right you can see how the pointers a and b are set when the swapper function is called.
If I want to send a block of memory into a function I can pass a pointer into the function and within the function we can use the pointer as the base of an array. I will use this trick when we want to print strings of text to our LCD panel.
Remember that pointers are strong magic. There is no particular need to understand all their ramifications to write good code for a PICmicro microcontroller, but you will need to have a good grasp of them if you write any larger programs.
Two pointers a and b, pointing to i and j respectively